﻿using Dt261.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Dt261.Views
{
    class DrawHearingImage
    {
       
        Bitmap imagedata2;

        private int topM = 36;
        private int rightM = 20;
        private double px;
        private double py;
        public DrawHearingImage()
        {


            px = (300 - yuandian.X - rightM) / 6.0;
            py = (yuandian.Y - topM) / 13.0;
        }
        private string Bindtitle = "听力测试报告";

        private Collection<string> hzs = new Collection<string> { "125", "250", "500", "1K", "2K", "4K", "8K" };
        private Collection<int> hzsint = new Collection<int> { 125, 250, 500, 750, 1000, 1500, 2000, 3000, 4000, 6000, 8000 };

        Dictionary<int, double> hzsPxValue = new Dictionary<int, double> { { 125, 0 }, { 250, 1 }, { 500, 2 },{ 750, 2.5 }, { 1000, 3 }, { 1500, 3.5 }, { 2000, 4 },
            { 3000, 4.5 }, { 4000, 5 },{ 6000, 5.5 }, { 8000, 6 } };

        //Dictionary<int, int> limitHz = new Dictionary<int, int> { { 125, 65 }, { 250, 85 }, { 500, 105 }, { 750, 105 },{ 1000, 105 }, { 1500, 105 }, { 2000, 105 },
        //    { 3000, 105 }, { 4000, 105 },{ 6000, 105 }, { 8000, 95 } };


        private List<Point> dataPoints = new List<Point>();
        private PointCollection coordinatePoints = new PointCollection();
        private List<Shape> pointEllipses = new List<Shape>();
        private List<Shape> pointEllipses2 = new List<Shape>();


        private List<Shape> pointBcEllipses = new List<Shape>();
        private List<Shape> pointBcEllipses2 = new List<Shape>();//
        Polyline curvePolyline = new Polyline();

        private Point yuandian = new Point(20, 280);

        Graphics chartCanvas;
        Graphics chartCanvas2;
        //var imagedata = new Bitmap(300, 300);
        //var sourcegra = Graphics.FromImage(imagedata);



        private PureToneResult selectPureToneResult;
        private MemberInfo selectMember;

        private int currentIndex;

        private string titleText;

        private string left_ac;
        private string right_ac;
        private string left_ac_mask;
        private string right_ac_mask;

        private string left_bc;
        private string right_bc;
        private string left_bc_mask;
        private string right_bc_mask;

        private string left_ff;
        private string right_ff;
        private string left_ff_mask;
        private string right_ff_mask;

        public string Left_ac { get => left_ac; set => left_ac = value; }
        public string Right_ac { get => right_ac; set => right_ac = value; }
        public string Left_ac_mask { get => left_ac_mask; set => left_ac_mask = value; }
        public string Right_ac_mask { get => right_ac_mask; set => right_ac_mask = value; }
        public string Left_bc { get => left_bc; set => left_bc = value; }
        public string Right_bc { get => right_bc; set => right_bc = value; }
        public string Left_bc_mask { get => left_bc_mask; set => left_bc_mask = value; }
        public string Right_bc_mask { get => right_bc_mask; set => right_bc_mask = value; }
        public string Left_ff { get => left_ff; set => left_ff = value; }
        public string Right_ff { get => right_ff; set => right_ff = value; }
        public string Left_ff_mask { get => left_ff_mask; set => left_ff_mask = value; }
        public string Right_ff_mask { get => right_ff_mask; set => right_ff_mask = value; }


        //type 0左 1右 2 左右一起
        public Bitmap getBitmapByPureToneResult(PureToneResult SelectPureToneResult,int type)
        {
            Bitmap imagedata;
            imagedata = new Bitmap(300, 300);
            chartCanvas = Graphics.FromImage(imagedata);
            chartCanvas.FillRectangle(System.Drawing.Brushes.White, 0, 0, 300, 300);
            DrawScale(chartCanvas);
            chartCanvas.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            chartCanvas2 = chartCanvas;
            //if (type == 2)
            //{
            //    chartCanvas2 = chartCanvas;
            //}
            //else
            //{
            //    //chartCanvas.fillRect(0, 0, 50, 50);
            //    imagedata2 = new Bitmap(300, 300);
            //    chartCanvas2 = Graphics.FromImage(imagedata2);
            //    chartCanvas2.FillRectangle(System.Drawing.Brushes.White, 0, 0, 300, 300);
            //    DrawScale(chartCanvas2);
            //}


            Left_ac = "pack://application:,,,/../Assets/Images/left_type_" + SelectPureToneResult.AcLeftType + ".png";
            Right_ac = "pack://application:,,,/../Assets/Images/right_type_" + SelectPureToneResult.AcRightType + ".png";
            Left_ac_mask = "pack://application:,,,/../Assets/Images/left_type_" + SelectPureToneResult.AcLeftMaskedType + ".png";
            Right_ac_mask = "pack://application:,,,/../Assets/Images/right_type_" + SelectPureToneResult.AcRightMaskedType + ".png";

            Left_bc = "pack://application:,,,/../Assets/Images/left_type_" + SelectPureToneResult.BcLeftType + ".png";
            Right_bc = "pack://application:,,,/../Assets/Images/right_type_" + SelectPureToneResult.BcRightType + ".png";
            Left_bc_mask = "pack://application:,,,/../Assets/Images/left_type_" + SelectPureToneResult.BcLeftMaskedType + ".png";
            Right_bc_mask = "pack://application:,,,/../Assets/Images/right_type_" + SelectPureToneResult.BcRightMaskedType + ".png";

            Left_ff = "pack://application:,,,/../Assets/Images/left_type_21.png";
            Right_ff = "pack://application:,,,/../Assets/Images/right_type_21.png";
            Left_ff_mask = "pack://application:,,,/../Assets/Images/left_type_23.png";
            Right_ff_mask = "pack://application:,,,/../Assets/Images/right_type_23.png";



      
            foreach (ResultDataSet dataset in SelectPureToneResult.DataSets)
            {
                Dictionary<int, TestItem> dict = new Dictionary<int, TestItem>();
                foreach (ResultEntry entry in dataset.Entrys)
                {
                    TestItem item = new TestItem();
                    item.Hz = entry.ValueX;
                    item.Db = entry.ValueY;
                    if (entry.PointState == 1)
                    {
                        item.Mask = true;
                        item.MaskV = 0;
                        //...
                    }
                    else
                    {
                        item.Mask = false;
                        item.MaskV = 0;
                        //...
                    }


                    if (entry.IsUserResp == 0)
                        item.IsUserResp = false;
                    else
                        item.IsUserResp = true;
                    item.MarkType = entry.MarkType;
                    item.abc = entry.Mmtype;
                    dict.Add(item.Hz, item);

                    //List<TestItem> listChild = this.rightResult.ToList();
                    //listChild.Sort(delegate (TestItem p1, TestItem p2) { return Comparer<int>.Default.Compare(p1.Hz, p2.Hz); });
                    ////List列表转为ObservableCollection集合
                    //this.rightResult = new ObservableCollection<TestItem>(listChild);
                }
                //this.IsRightEar 

                if(type == 2 || (dataset.IsRight == type))
                UpdateTestItem(dict, dataset.IsRight == 1, dataset.HeadsetMode, SelectPureToneResult.State);

            }

#if DEBUG
            var basePath = Environment.CurrentDirectory;

            if(imagedata != null)
            {
                string jpg = System.IO.Path.Combine(basePath, "1.png");
                imagedata.Save(jpg, System.Drawing.Imaging.ImageFormat.Png);//保存图片到
            }

            //if (imagedata2 != null)
            //{
            //    string jpg2 = System.IO.Path.Combine(basePath, "2.jpeg");
            //    imagedata2.Save(jpg2, System.Drawing.Imaging.ImageFormat.Jpeg);//保存图片
            //}
            
           
            
#endif
            return imagedata;
        }

        private void UpdateTestItem(Dictionary<int, TestItem> list, bool isRight, int mmtype = 0, int bcneedlink = 0)
        {

            if (mmtype == 0)
            {
                if (isRight)
                {
  
                    if (list == null) return;

                    TestItem lastitem = null;
                    for (int i = 0; i < this.hzsint.Count(); i++)
                    {
                        //(40,280)原点坐标,上面空45，右边空80
                        // this.chartCanvas.Children.Clear();
                        if (list.ContainsKey(this.hzsint[i]))
                        {
                            TestItem item = list[this.hzsint[i]];
                            if (item.Mask == true)
                            {
                                DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                                    topM + (10 + item.Db) / 10.0 * py,
                                    item.MarkType != 0 ? item.MarkType : 10,
                                    true,
                                    chartCanvas,
                                    pointEllipses);

                            }
                            else
                            {


                               DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                         topM + (10 + item.Db) / 10.0 * py,
                         item.MarkType != 0 ? item.MarkType : 1,
                         true,
                         this.chartCanvas,
                         pointEllipses);
                            }



                            if (item.IsUserResp != true)
                            {
                                DrawNoRespIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                                   topM + (10 + item.Db) / 10.0 * py,
                                   isRight,
                                    this.chartCanvas,
                                   pointEllipses);

                            }


                            if (lastitem != null)
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(Color.FromRgb(0xff, 0, 0));

                                //line.Y1 = topM + (10 + lastitem.Db) / 10.0 * py;
                                //line.X1 = yuandian.X + hzsPxValue[lastitem.Hz] * px;
                                //line.Y2 = topM + (10 + item.Db) / 10.0 * py;
                                //line.X2 = yuandian.X + hzsPxValue[item.Hz] * px;
                                //line.StrokeThickness = 1;
                                //this.chartCanvas.Children.Add(line);
                                //pointEllipses.Add(line);
                                System.Drawing.Color color2 = System.Drawing.Color.FromArgb(0xff, 0, 0);
                                this.chartCanvas.DrawLine(new System.Drawing.Pen(color2),(float)( yuandian.X + hzsPxValue[lastitem.Hz] * px), (float)(topM + (10 + lastitem.Db) / 10.0 * py),
                                    (float)(yuandian.X + hzsPxValue[item.Hz] * px), (float)(topM + (10 + item.Db) / 10.0 * py));


                            }


                            lastitem = item;



                        }

                    }

                }
                else
                {
                    //foreach (Shape dataEllipse in pointEllipses2)
                    //{
                    //    this.chartCanvas2.Children.Remove(dataEllipse);
                    //}

                    if (list == null) return;
                    TestItem lastitem = null;
                    for (int i = 0; i < this.hzsint.Count(); i++)
                    {
                        //(40,280)原点坐标,上面空45，右边空80
                        // this.chartCanvas.Children.Clear();
                        if (list.ContainsKey(this.hzsint[i]))
                        {
                            TestItem item = list[this.hzsint[i]];

                            if (item.IsUserResp != true)
                            {
                                DrawNoRespIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                                   topM + (10 + item.Db) / 10.0 * py,
                                   isRight,
                                    this.chartCanvas2,
                                   pointEllipses2);

                            }


                            if (item.Mask == true)
                            {


                                DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                         topM + (10 + item.Db) / 10.0 * py,
                         item.MarkType != 0 ? item.MarkType : 9,
                         false,
                         this.chartCanvas2,
                         pointEllipses2);
                            }
                            else
                            {
                               DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
        topM + (10 + item.Db) / 10.0 * py,
        item.MarkType != 0 ? item.MarkType : 2,
        false,
        this.chartCanvas2,
        pointEllipses2);

                            }


                            if (lastitem != null)
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0xff));

                                //line.Y1 = topM + (10 + lastitem.Db) / 10.0 * py;
                                //line.X1 = yuandian.X + hzsPxValue[lastitem.Hz] * px;
                                //line.Y2 = topM + (10 + item.Db) / 10.0 * py;
                                //line.X2 = yuandian.X + hzsPxValue[(item.Hz)] * px;
                                //line.StrokeThickness = 1;


                                //this.chartCanvas2.Children.Add(line);
                                //pointEllipses2.Add(line);

                                System.Drawing.Color color2 = System.Drawing.Color.FromArgb(0, 0, 0xff);
                                this.chartCanvas2.DrawLine(new System.Drawing.Pen(color2), (float)(yuandian.X + hzsPxValue[lastitem.Hz] * px), (float)(topM + (10 + lastitem.Db) / 10.0 * py),
                                    (float)(yuandian.X + hzsPxValue[item.Hz] * px), (float)(topM + (10 + item.Db) / 10.0 * py));

                            }

                            lastitem = item;



                        }

                    }
                }
            }


            else if (mmtype == 1)
            {
                if (isRight)
                {
 

                    if (list == null) return;


                    TestItem lastitem = null;
                    for (int i = 0; i < this.hzsint.Count(); i++)
                    {
                        //(40,280)原点坐标,上面空45，右边空80
                        // this.chartCanvas.Children.Clear();
                        if (list.ContainsKey(this.hzsint[i]))
                        {
                            TestItem item = list[this.hzsint[i]];


                            if (item.Mask == true)
                            {
                               DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                              topM + (10 + item.Db) / 10.0 * py,
                              item.MarkType != 0 ? item.MarkType : 6,
                              isRight,
                              this.chartCanvas,
                              pointBcEllipses);



                            }
                            else
                            {
                               DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                                   topM + (10 + item.Db) / 10.0 * py,
                                   item.MarkType != 0 ? item.MarkType : 4,
                                   isRight,
                                   this.chartCanvas,
                                   pointBcEllipses);

                            }





                            if (item.IsUserResp != true)
                            {

                                DrawNoRespIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                           topM + (10 + item.Db) / 10.0 * py,
                           isRight,
                            this.chartCanvas,
                           pointBcEllipses);

                            }

                            //骨导默认不连线
                            if (lastitem != null && bcneedlink == 1)
                            {

                                //Polyline x_scale = new Polyline();
                                //x_scale.Stroke = new SolidColorBrush(System.Drawing.Color.FromRgb(0xff, 0, 0));
                                //x_scale.StrokeDashArray.Add(10);
                                //x_scale.StrokeDashArray.Add(20);
                                //;
                                //x_scale.StrokeThickness = 0.5;
                                //x_scale.Points.Add(new Point((int)(yuandian.X + hzsPxValue[lastitem.Hz] * px),(int)(topM + (10 + lastitem.Db) / 10 * py)));
                                //x_scale.Points.Add(new Point(yuandian.X + hzsPxValue[item.Hz] * px, topM + (10 + item.Db) / 10 * py));


                                //this.chartCanvas.Children.Add(x_scale);
                                //pointBcEllipses.Add(x_scale);


                                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
                                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                                pen.DashPattern = new float[] { 5, 5 };

                                chartCanvas2.DrawLine(pen, (int)(yuandian.X + hzsPxValue[lastitem.Hz] * px), (int)(topM + (10 + lastitem.Db) / 10.0 * py),
                                    (int)(yuandian.X + hzsPxValue[item.Hz] * px), (int)(topM + (10 + item.Db) / 10.0 * py));

                            }


                            lastitem = item;



                        }

                    }

                }
                else
                {
                    //foreach (Shape dataEllipse in pointBcEllipses2)
                    //{
                    //    this.chartCanvas2.Children.Remove(dataEllipse);
                    //}

                    if (list == null) return;
                   // PreviewPageViewModel vm = DataContext as PreviewPageViewModel;


                    TestItem lastitem = null;
                    for (int i = 0; i < this.hzsint.Count(); i++)
                    {
                        //(40,280)原点坐标,上面空45，右边空80
                        // this.chartCanvas.Children.Clear();
                        if (list.ContainsKey(this.hzsint[i]))
                        {
                            TestItem item = list[this.hzsint[i]];

                            if (item.IsUserResp != true)
                            {
                                DrawNoRespIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                             topM + (10 + item.Db) / 10.0 * py,
                             isRight,
                              this.chartCanvas2,
                             pointBcEllipses2);

                            }


                            if (item.Mask == true)
                            {
                                DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                              topM + (10 + item.Db) / 10.0 * py,
                              item.MarkType != 0 ? item.MarkType : 5,
                              isRight,
                              this.chartCanvas2,
                              pointBcEllipses2);



                            }
                            else
                            {
                               DrawIconByType(yuandian.X + hzsPxValue[item.Hz] * px,
                                   topM + (10 + item.Db) / 10.0 * py,
                                   item.MarkType != 0 ? item.MarkType : 3,
                                   isRight,
                                   this.chartCanvas2,
                                   pointBcEllipses2);

                            }

                            if (lastitem != null && bcneedlink == 1)
                            {


                                //Polyline x_scale = new Polyline();
                                //x_scale.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0xff));
                                //x_scale.StrokeDashArray.Add(10);
                                //x_scale.StrokeDashArray.Add(20);
                                //;
                                //x_scale.StrokeThickness = 0.5;
                                //x_scale.Points.Add(new Point(, ));
                                //x_scale.Points.Add(new Point(, ));


                                //this.chartCanvas2.Children.Add(x_scale);
                                //pointBcEllipses2.Add(x_scale);



                                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
                                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                                pen.DashPattern = new float[] { 5, 5 };

                                chartCanvas2.DrawLine(pen, (int)(yuandian.X + hzsPxValue[lastitem.Hz] * px), (int)(topM + (10 + lastitem.Db) / 10.0 * py),
                                    (int)(yuandian.X + hzsPxValue[item.Hz] * px), (int)(topM + (10 + item.Db) / 10.0 * py));



                            }

                            lastitem = item;



                        }

                    }
                }
            }
        }

        //public void getImage()
        //{
        //    var basePath = Environment.CurrentDirectory;

        //    string jpg = System.IO.Path.Combine(basePath, "1.jpeg");
        //    string jpg2 = System.IO.Path.Combine(basePath, "2.jpeg");
        //    //先创建一个画布，来绘制一个宽长为：300，300的画布。
        //    //var imagedata = new Bitmap(300, 300);
        //    //var sourcegra = Graphics.FromImage(imagedata);//存入画布
        //    //sourcegra.DrawString("douting", new Font("宋体", 20, System.Drawing.FontStyle.Regular), new SolidBrush(Color.White), 20, 100);//在画布绘制字体
            
        //    imagedata2.Save(jpg2, System.Drawing.Imaging.ImageFormat.Jpeg);//保存图片到D盘
        //}



        public static void DrawIconByType(double _centerX, double _centerY, int type, bool isright, Graphics graphics, List<Shape> wheretoadd = null)
        {
            int centerX = (int)_centerX; int centerY = (int)_centerY;
            int width = 10;
            int r = width;
           // Color color = isright ? Color.FromRgb(0xff, 0, 0) : Color.FromRgb(0, 0, 0xff);
            System.Drawing.Color color2 = isright ? System.Drawing.Color.FromArgb(0xff, 0, 0) : System.Drawing.Color.FromArgb(0, 0, 0xff);

            // if (isright)
            {
                switch (type)
                {
                    case 1://右耳非掩蔽
                        {
                            //Ellipse dataEllipse = new Ellipse();
                            //// dataEllipse.Fill = new SolidColorBrush(color);
                            //dataEllipse.Stroke = new SolidColorBrush(color);
                            //dataEllipse.Width = 10;
                            //dataEllipse.Height = 10;
                            //Canvas.SetTop(dataEllipse, centerY - 5);
                            //Canvas.SetLeft(dataEllipse, centerX - 5);
                            //canves.Children.Add(dataEllipse);
                            //wheretoadd.Add(dataEllipse);


                            graphics.DrawEllipse(new System.Drawing.Pen(color2), centerX - r/2, centerY - r/2,r,r);

                        }
                        break;
                    case 2://左耳非掩蔽
                        {
                            //Line line = new Line();
                            //line.Stroke = new SolidColorBrush(color);
                            //line.Y1 = centerY - 5;
                            //line.X1 = centerX - 5;
                            //line.Y2 = centerY + 5;
                            //line.X2 = centerX + 5;
                            //line.StrokeThickness = 1;
                            //canves.Children.Add(line);
                            //wheretoadd.Add(line);

                            graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX -  r/2, centerY - r/2), new Point(centerX + r/2, centerY +  r/2));

                        }
                        {
                            //Line line = new Line();
                            //line.Stroke = new SolidColorBrush(color);
                            //line.Y1 = centerY + 5;
                            //line.X1 = centerX - 5;
                            //line.Y2 = centerY - 5;
                            //line.X2 = centerX + 5;
                            //line.StrokeThickness = 1;
                            //canves.Children.Add(line);
                            //wheretoadd.Add(line);

                            graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX + r/2, centerY - r/2));

                        }
                        break;
                    case 3:
                        {
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY;
                                //line.X1 = centerX + 5;
                                //line.Y2 = line.Y1 + 5;
                                //line.X2 = line.X1 - 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY), new Point(centerX - r, centerY + r/2));

                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY;
                                //line.X1 = centerX + 5;
                                //line.Y2 = line.Y1 - 5;
                                //line.X2 = line.X1 - 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY), new Point(centerX - r, centerY - r / 2));

                            }
                        }
                        break;
                    case 4:
                        {
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 + 5;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY), new Point(centerX + r/2, centerY + r / 2));

                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 - 5;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY), new Point(centerX + r / 2, centerY - r / 2));
                            }
                        }
                        break;
                    case 5://xgwen
                        {
                            {
                                {
                                    //Line line = new Line();
                                    //line.Stroke = new SolidColorBrush(color);

                                    //line.Y1 = centerY - 5;
                                    //line.X1 = centerX + 5;
                                    //line.Y2 = line.Y1 + 10;
                                    //line.X2 = line.X1;
                                    //line.StrokeThickness = 1;
                                    //canves.Children.Add(line);
                                    //wheretoadd.Add(line);

                                    graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY-r/2), new Point(centerX + r / 2, centerY + r/2));
                                }
                                {
                                    //Line line = new Line();
                                    //line.Stroke = new SolidColorBrush(color);

                                    //line.Y1 = centerY - 5;
                                    //line.X1 = centerX + 5;
                                    //line.Y2 = line.Y1 + 5;
                                    //line.X2 = line.X1 - 10;
                                    //line.StrokeThickness = 1;
                                    //canves.Children.Add(line);
                                    //wheretoadd.Add(line);

                                    graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY - r / 2), new Point(centerX - r / 2, centerY));
                                }
                                {
                                    //Line line = new Line();
                                    //line.Stroke = new SolidColorBrush(color);

                                    //line.Y1 = centerY + 5;
                                    //line.X1 = centerX + 5;
                                    //line.Y2 = line.Y1 - 5;
                                    //line.X2 = line.X1 - 10;
                                    //line.StrokeThickness = 1;
                                    //canves.Children.Add(line);
                                    //wheretoadd.Add(line);

                                    graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY + r / 2), new Point(centerX - r / 2, centerY));
                                }
                            }
                        }
                        break;
                    case 6://xgwen
                        {
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY + 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 - 10;
                                //line.X2 = line.X1;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX - r / 2, centerY - r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY + 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 - 5;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX + r / 2, centerY));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 + 5;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY - r / 2), new Point(centerX + r / 2, centerY));
                            }
                        }
                        break;

                    case 7:
                        {
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 + 10;
                                //line.X2 = line.X1;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY - r / 2), new Point(centerX - r / 2, centerY + r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 + 0;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY - r / 2), new Point(centerX + r / 2, centerY - r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY + 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }
                        }
                        break;
                    case 8:
                        {
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX + 5;
                                //line.Y2 = line.Y1 + 10;
                                //line.X2 = line.X1;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX + r / 2, centerY - r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1 + 0;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY - r / 2), new Point(centerX + r / 2, centerY - r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY + 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }
                        }
                        break;
                    case 9://
                        {
                            //Rectangle rect = new Rectangle();
                            ////(40 + px * hzsint.IndexOf(hz), 280, px, py * (120 - value));

                            //rect.Stroke = new SolidColorBrush(color);

                            //rect.Height = 10.0;


                            //rect.Width = 10.0;
                            //Canvas.SetLeft(rect, centerX - 5);
                            //Canvas.SetTop(rect, centerY - 5);

                            //canves.Children.Add(rect);
                            //wheretoadd.Add(rect);
                            graphics.DrawRectangle(new System.Drawing.Pen(color2), centerX - r / 2, centerY - r / 2,r,r);
                            
                        }

                        break;
                    case 10:
                        {
                            //三角形
                            {

                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX , centerY-r/2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX;
                                //line.Y2 = line.Y1 + 10;
                                //line.X2 = line.X1 + 5;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX , centerY - r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY + 5;
                                //line.X1 = centerX - 5;
                                //line.Y2 = line.Y1;
                                //line.X2 = line.X1 + 10;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r / 2, centerY + r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }
                        }
                        break;
                    case 13:
                        {
                            //
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX;
                                //line.Y2 = line.Y1 + 10;
                                //line.X2 = line.X1 - 5;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX , centerY - r / 2), new Point(centerX - r / 2, centerY + r / 2));
                            }
                            {
                                //Line line = new Line();
                                //line.Stroke = new SolidColorBrush(color);

                                //line.Y1 = centerY - 5;
                                //line.X1 = centerX;
                                //line.Y2 = line.Y1 + 10;
                                //line.X2 = line.X1 + 5;
                                //line.StrokeThickness = 1;
                                //canves.Children.Add(line);
                                //wheretoadd.Add(line);
                                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX , centerY - r / 2), new Point(centerX + r / 2, centerY + r / 2));
                            }

                        }
                        break;
                }
            }

        }
        public static void DrawNoRespIconByType(double _centerX, double _centerY, bool isright, Graphics graphics, List<Shape> wheretoadd = null)
        {
            int centerX =(int) _centerX; int centerY =(int) _centerY;
            int r = 4;
            System.Windows.Media.Color color = isright ? System.Windows.Media.Color.FromRgb(0xff, 0, 0) : System.Windows.Media.Color.FromRgb(0, 0, 0xff);

            System.Drawing.Color color2 = isright ? System.Drawing.Color.FromArgb(0xff, 0, 0) : System.Drawing.Color.FromArgb(0, 0, 0xff);

            {
                //Line line = new Line();
                //line.Stroke = new SolidColorBrush(color);

                //line.Y1 = centerY + 4;
                //line.X1 = centerX - 4;
                //line.Y2 = line.Y1 + 4;
                //line.X2 = line.X1 - 4;
                //line.StrokeThickness = 1;

                // wheretoadd.Add(line);

                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - r, centerY + r), new Point(centerX - 2*r, centerY + 2*r));
            }
            {
                //Line line = new Line();
                //line.Stroke = new SolidColorBrush(color);

                //line.Y1 = centerY + 8;
                //line.X1 = centerX - 8;
                //line.Y2 = line.Y1 - 4;
                //line.X2 = line.X1;
                //line.StrokeThickness = 1;
                //canves.Children.Add(line);
                //wheretoadd.Add(line);

                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - 2*r, centerY + 2*r), new Point(centerX - 2 * r, centerY + r));
            }
            {
                //Line line = new Line();
                //line.Stroke = new SolidColorBrush(color);

                //line.Y1 = centerY + 8;
                //line.X1 = centerX - 8;
                //line.Y2 = line.Y1;
                //line.X2 = line.X1 + 4;
                //line.StrokeThickness = 1;
                //canves.Children.Add(line);
                //wheretoadd.Add(line);

                graphics.DrawLine(new System.Drawing.Pen(color2), new Point(centerX - 2 * r, centerY + 2 * r), new Point(centerX -  r, centerY + 2*r));
            }
        }


        private void DrawScale(Graphics canvas)
        {

            int Width = 300;
            //int 

            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Near;


            for (int i = 0; i < 4; i += 1)//作480个刻度，因为当前x轴长 480px，每10px作一个小刻度，还预留了一些小空间
            {
                //原点 O=(40,280),s

                //Polyline x_scale = new Polyline();
                //x_scale.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                //x_scale.StrokeDashArray.Add(10);
                //x_scale.StrokeDashArray.Add(20);
                ///// Line x_scale = new Line();
                ////x_scale.StrokeEndLineCap = PenLineCap.Triangle;
                ////x_scale.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                //x_scale.StrokeThickness = 0.1;
                //x_scale.Points.Add(new Point, ));
                //x_scale.Points.Add(new Point(, topM));    //在x轴上的刻度线，起点和终点相同

                ////x_scale.Y1 = yuandian.Y;           //与原点坐标的y=280，相同 
                ////x_scale.Y2 = topM;


                //canvas.Children.Add(x_scale);


                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Gray, 1 / 4);
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                pen.DashPattern = new float[] { 5, 10 };

                canvas.DrawLine(pen, (int)(yuandian.X + (2.5 + i) * (Width - yuandian.X - rightM) / 6.0), (int)(yuandian.Y),
                    (int)(yuandian.X + (2.5 + i) * (Width - yuandian.X - rightM) / 6.0), (int)topM);

            }
            //(40,280)原点坐标,上面空45，右边空80

            //"1500", "3000", "6000",

            for (int i = 0; i < 7; i += 1)//作480个刻度，因为当前x轴长 480px，每10px作一个小刻度，还预留了一些小空间
            {
                //原点 O=(40,280),s
                //Line x_scale = new Line();
                //x_scale.StrokeEndLineCap = PenLineCap.Triangle;
                //x_scale.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                //x_scale.StrokeThickness = 0.1;
                //x_scale.X1 = yuandian.X + i * (canvas.Width - yuandian.X - rightM) / 6.0;
                //x_scale.X2 = x_scale.X1;    //在x轴上的刻度线，起点和终点相同

                //x_scale.Y1 = yuandian.Y;           //与原点坐标的y=280，相同 
                //x_scale.Y2 = topM;


                //canvas.Children.Add(x_scale);

                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Gray, 1 / 4);
                canvas.DrawLine(pen, new Point((int)(yuandian.X + i * (Width - yuandian.X - rightM) / 6.0), yuandian.Y), new Point((int)(yuandian.X + i * (Width - yuandian.X - rightM) / 6.0), topM));


                {
                    //TextBlock x_ScaleLabel = new TextBlock();

                    //x_ScaleLabel.TextAlignment = TextAlignment.Left;
                    //x_ScaleLabel.Width = (canvas.Width - yuandian.X - rightM) / 6.0;
                    //x_ScaleLabel.FontSize = 12;
                    //x_ScaleLabel.Text = hzs[i]; ;//只给大刻度添加标签，每50px添加一个标签

                    //Canvas.SetLeft(x_ScaleLabel, yuandian.X + i * (canvas.Width - yuandian.X - rightM) / 6.0 - 12);//40是原点的坐标，-12是为了让标签看的位置剧中一点
                    //Canvas.SetTop(x_ScaleLabel, yuandian.Y + 10);//让标签字往下移一点

                    //canvas.Children.Add(x_ScaleLabel);

                    canvas.DrawString(hzs[i], new Font("宋体", 5, System.Drawing.FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 
                        (int)(yuandian.X + i * (Width - yuandian.X - rightM) / 6.0 -8), yuandian.Y + 5,sf);//在画布绘制字体

        }


            }

            for (int i = 0; i < 14; i += 1)//由于y轴短一些，所以在此作出判断，只作25个刻度
            {
                //作出Y轴的刻度
                //Line y_scale = new Line();
                //y_scale.StrokeEndLineCap = PenLineCap.Triangle;
                //y_scale.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));

                //y_scale.X1 = yuandian.X;            //原点x=40，在y轴上的刻度线的起点与原点相同
                //y_scale.StrokeThickness = 0.1;

                //y_scale.X2 = canvas.Width - rightM;
                //y_scale.Y1 = topM + i * ((yuandian.Y - topM) / 13.0);  //每10px作一个刻度 
                //y_scale.Y2 = y_scale.Y1;    //起点和终点y坐标相同 
                //canvas.Children.Add(y_scale);

                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Gray, 1 / 4);
                canvas.DrawLine(pen, new Point((int)(yuandian.X), (int)(topM + i * ((yuandian.Y - topM) / 13.0))), 
                    new Point((int)(Width - rightM), (int)(topM + i * ((yuandian.Y - topM) / 13.0))));


                if (i % 2 == 1)
                {
                    //TextBlock y_ScaleLabel = new TextBlock();
                    //y_ScaleLabel.TextAlignment = TextAlignment.Center;
                    //y_ScaleLabel.Width = 30;
                    //y_ScaleLabel.FontSize = 12;
                    //y_ScaleLabel.Text = (-10 + i * 10).ToString();
                    //Canvas.SetLeft(y_ScaleLabel, yuandian.X - 30);              //-25px是字体大小的偏移
                    //Canvas.SetTop(y_ScaleLabel, topM + i * ((yuandian.Y - topM) / 13.0) - 10);  //280px是原点的坐标，同样-6是为了让标签不要上坐标轴叠上

                    //canvas.Children.Add(y_ScaleLabel);

                    canvas.DrawString((-10 + i * 10).ToString(), new Font("宋体", 5, System.Drawing.FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black),
                    (int)(yuandian.X - 20), (int)(topM - 5 + i * ((yuandian.Y - topM) / 13.0)), sf);//在画布绘制字体
                }

            }
            {
                //TextBlock x_ScaleLabel = new TextBlock();
                //x_ScaleLabel.Text = "Hz"; ;//只给大刻度添加标签，每50px添加一个标签

                //Canvas.SetLeft(x_ScaleLabel, canvas.Width - rightM + 12);//40是原点的坐标，-12是为了让标签看的位置剧中一点
                //Canvas.SetTop(x_ScaleLabel, yuandian.Y + 10);//让标签字往下移一点

                //canvas.Children.Add(x_ScaleLabel);

                //TextBlock y_ScaleLabel = new TextBlock();

                //y_ScaleLabel.Text = "dBHL";
                //Canvas.SetLeft(y_ScaleLabel, yuandian.X - 30);
                //Canvas.SetTop(y_ScaleLabel, topM - 30);

                //canvas.Children.Add(y_ScaleLabel);

                canvas.DrawString("Hz", new Font("宋体", 6, System.Drawing.FontStyle.Italic), new SolidBrush(System.Drawing.Color.Black),
      (int)(Width - rightM +3 ), (int)(yuandian.Y + 5), sf);//在画布绘制字体


                canvas.DrawString("dBHL", new Font("宋体", 6, System.Drawing.FontStyle.Italic), new SolidBrush(System.Drawing.Color.Black),
      (int)(yuandian.X -10), (int)(topM - 15), sf);//在画布绘制字体
            }

        }

    }
}
